import axios from 'axios';


axios.defaults.withCredentials = true;
axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';  //证明是ajax 请求

const service = axios.create({
  /*baseURL: 'http://152.136.62.89:8085',*/
  baseURL: 'http://localhost:8085',
  timeout: 25000,
  withCredentials: true
});

service.interceptors.request.use(config =>{
  //不支持
  //config.headers['X-Frame-Options']="DENY"
  //config.headers['X-Content-Type-Options']="nosniff"
  config.headers['Content-Type'] = 'application/json; charset=UTF-8'
  return config;
},error => {
  alert(error);
  return Promise.reject(error);
});

service.interceptors.response.use(response=>{
  const res = response.data;
  if(!res){
    this.$swal({
      allowOutsideClick:false,
      type: 'error',
      title:'服务已断开，请检查网络'
    })
  }
  return response;
},error => {
  alert(error.response)
  return Promise.reject(error)
})

export default service;
